<?php

# http://projects:8081/cdapp-2kt-api/api/seat_status_get.php

include_once '_portal.php';

forbidden_acc();

// step-1
// clear_planning
$sql_arr = [
  "UPDATE `2kt_seat_status` SET `planningSectorCodes`= NULL WHERE `sectorCodes` = `planningSectorCodes`",
  "UPDATE `2kt_seat_status` SET `planningFrequency`= NULL WHERE `frequency` = `planningFrequency`",
];
exec_sql_array($sql_arr);

// step-2
// get all seat status
$sql = "SELECT * FROM `2kt_seat_status`";
$data = exec_sql($sql);

// step-3
// add version
$version = param('ATCOS_SECTOR_TIMESTAMP_RECIVE');
$freshness = timestamp() - intval($version);
$available = true;

// step-4
// output
if ($data) {
  $data = query_parse($data);
  output(['success' => true, 'content' => $data, 'version' => $version, 'available' => $available, 'freshness' => $freshness]);
} else {
  output(['success' => false, 'content' => $data, 'version' => $version, 'available' => $available, 'freshness' => $freshness]);
}

die();
